package Game;

import Java01.Poker;
import Java01.PokerManager;

import java.util.Random;


public class ComputerGame implements gameEnvironment{
    Random r = new Random();
    int jackPot;
    public void begin(PersonPlayer player){
        player.initID();
        player.initName();
        player.initMoney();
        player.pokerPrint();
    }
    @Override
    public int bet(PersonPlayer player) {
        int money = player.getMoney() / 100;
        int giveMoney = r.nextInt(money) * 100;
        player.setMoney(player.getMoney() - giveMoney);
        System.out.println("电脑" + player.getID() +"投注： " + giveMoney);
        System.out.println("电脑" + player.getID() +"剩余金额为：" + player.getMoney());
        jackPot += player.getMoney();
        System.out.println(player);
        return giveMoney;
    }

    @Override
    public int withBet(PersonPlayer player, int money) {
        System.out.println(player.getName() + "总金额为：" + player.getMoney());
        int n = r.nextInt(2);
         if (n == 0){
            int giveMoney = r.nextInt(player.getMoney() / 100) * 100;
            while(money < giveMoney){
                giveMoney = r.nextInt(player.getMoney() / 100) * 100;
            }
            jackPot += money;
            player.setMoney(player.getMoney() - giveMoney);
            System.out.println("电脑" + player.getID() +"跟注： " +giveMoney);
            System.out.println("电脑" + player.getID() +"剩余金额为： " + player.getMoney());
        }else System.out.println("电脑" + player.getID() +"跳过跟注");
         return jackPot;
    }

    @Override
    public void disCard(PersonPlayer player,int flag) {
        int n = r.nextInt(10) % 2;
        if (n == 0 || flag == 1){
            System.out.println("电脑" + player.getID() + "选择弃牌");
        }
        System.out.println("电脑" + player.getID() +"剩余金额为： " + player.getMoney());
    }

    @Override
    public int allIn(PersonPlayer player,int flag) {
        int n = r.nextInt(10) % 2;
        if (n == 0 && flag == 0){
            jackPot = player.getMoney();
            player.setMoney(0);
            System.out.println("电脑" + player.getID() +"梭哈了，" + "剩余金额为 ：" + player.getMoney());
            return 1;
        }else {
            System.out.println("电脑" + player.getID() + "跳过梭哈");
            disCard(player,1);
        }
        return 0;
    }

    @Override
    public boolean CompareCard(PersonPlayer player,PersonPlayer anotherPlayer,PokerManager pokerManager) {
//        player.setPoker(pokerManager.getPoker());
        return player.compareTo(anotherPlayer.getPoker());
    }
}
